<template>
  <el-card class="recommend">
    <h4>
      <svg-icon name="recommend" width="20" height="20"></svg-icon>推荐文章
    </h4>
    <div class="container">
      <div class="big-article">
        <img src="@/assets/images/banner3.jpg" alt="" />

        <p>这里是公告消息区域</p>
      </div>
      <div class="articles">
        <div class="article-item" v-for="item in articleList" :key="item.id">
          <div class="pic">
            <img v-lazy="item.titleImg" alt="" />
          </div>
          <div class="info">
            <p>{{ item.title }}</p>
            <div class="time">{{ formatData(item.updateTime||item.createTime).split(" ")[0]}}<br><i>{{ formatData(item.updateTime||item.createTime).split(" ")[1] }}</i></div>
          </div>
        </div>
      </div>
    </div>
  </el-card>
</template>
<script setup>
import { formatData } from "@/utils/formatData.js";
import { ref, onMounted, reactive } from "vue";
import { getArticleList } from "@/api/article.js";
let articleList = reactive({});
onMounted(() => {
  getList();
});

const getList = async () => {
  const res = await getArticleList();
  const arr = res.data.filter(item=>item.isRecommend==1);
  articleList = Object.assign(articleList, arr);
  console.log(articleList, "list");
};


</script>
<style lang="scss" scoped>
:deep .el-card__body {
  padding: 0;
}
.recommend {
  border-radius: 5px;
  padding: 10px;
  h4 {
    display: flex;
    :deep svg {
      vertical-align: -4px;
      margin-right: 5px;
    }
    padding-bottom: 10px;
    background-image: linear-gradient(0deg, #000, #000);
    background-repeat: no-repeat;
    background-size: 10% 4px;
    background-position: left bottom;
    transition: background 0.5s ease-out;
  }
  &:hover {
    h4 {
      background-size: 30% 4px;
    }
    box-shadow: 1px 1px 10px 5px $shadowcolor;
  }
  .container {
    padding: 10px;
    // 大屏文章
    .big-article {
      cursor: pointer;
      width: 100%;
      position: relative;
      overflow: hidden;
      height: 150px;
      border-radius: 5px;
      margin-bottom: 20px;
      img {
        object-fit: cover;
        overflow: hidden;
        border-radius: 5px;
        width: 100%;
        height: 100%;
        transition: all 0.5s ease-out;
        &:hover {
          transform: scale(1.1);
        }
      }

      p {
        font-size: 0.9em;
        position: absolute;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        color: #fff;
      }
    }
    // 文章列表
    .articles {
      .article-item {
        width: 100%;
        display: flex;
        margin-bottom: 20px;
        .pic {
          overflow: hidden;
          border-radius: 5px;
          width: 120px;
          height: 75px;
          img {
            overflow: hidden;
            border-radius: 5px;
            width: 100%;
            height: 100%;
            transition: all 0.5s ease-out;
            &:hover {
              transform: scale(1.1);
            }
          }
        }
        .info {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          font-size: 16px;
          flex: 1;
          margin-left: 10px;
          p {
            font-weight: 500;
            &:hover {
              color: $strong;
            }
            font-size: 16px;
            display: -webkit-box;
            overflow: hidden;
            text-overflow: ellipsis;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
          }
          .time {
            margin-top: 10px;
            font-size:12px;
          }
        }
      }
    }
  }
}
</style>
